package com.jiguang.shangcheng.servlet;

import com.jiguang.shangcheng.dao.AdminDao;
import com.jiguang.shangcheng.pojo.Order;
import com.jiguang.shangcheng.pojo.OrderList;
import com.jiguang.shangcheng.pojo.Product;
import com.jiguang.shangcheng.pojo.User;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/admin_selectOrderById")
public class adminSelectById extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置字符集
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("UTF-8");

        //获取信息
        String id = req.getParameter("id");
        String cp = req.getParameter("cp");

        //通过id查询该订单的信息
        AdminDao adminDao = new AdminDao();
        Order order = adminDao.selectOrderByid(Integer.parseInt(id));

        OrderList orderList = new OrderList();
        orderList.setId(order.getId());
        orderList.setState(order.getState());
        orderList.setCreateTime(order.getCreateTime());
        //查询买家信息
        User user = adminDao.selectUserByid(order.getUserId());
        orderList.setUsername(user.getNetname());
        //查询商品名称
        Product product = adminDao.selectProductByid(order.getProductId());
        orderList.setProductname(product.getName());
        orderList.setPrice(product.getPrice());
        //查询卖家信息
        User user1 = adminDao.selectUserByid(product.getUserId());
        orderList.setShopname(user1.getNetname());

        req.setAttribute("o",orderList);
        req.setAttribute("cp",cp);

        req.getRequestDispatcher("admin_inserOrder.jsp").forward(req,resp);
    }
}
